#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import os
import shutil

gamedir = "E:/gamecopy/"
backupdir = "E:/SVN/SGSDK/SGTools/SGAutoPack/autopack_v4_ppl2/temp/"

umeng_lib_file = gamedir + "libs/com.umeng.message.lib_v2.2.0.jar"
umeng_lib_noutdid_file = gamedir + "libs/com.umeng.message.lib_v2.2.0-noutdid.jar"
mmsdk_lib_file = gamedir + "libs/libammsdk.jar"
backup_umeng_lib_file = backupdir + "com.umeng.message.lib_v2.2.0.jar"
backup_umeng_noutdid_lib_file = backupdir + "com.umeng.message.lib_v2.2.0-noutdid.jar"
backup_lib_mmsdk_file = backupdir + "libammsdk.jar"

#调整资源
def channelCustomOperBegin():
	print("begin , this is qihoo !")
	checkDirExist()
	
	if(False == os.path.exists(umeng_lib_file)):
		print("channelCustomOperBegin() , file ",umeng_lib_file,"is not exist!")
		return
	if(False == os.path.exists(backup_umeng_lib_file)):
		print("channelCustomOperBegin() , file ",backup_umeng_lib_file,"is not exist!")
		return
	if(False == os.path.exists(backup_umeng_noutdid_lib_file)):
		print("channelCustomOperBegin() , file ",backup_umeng_noutdid_lib_file,"is not exist!")
		return
	if(False == os.path.exists(mmsdk_lib_file)):
		print("channelCustomOperBegin() , file ",mmsdk_lib_file,"is not exist!")
		return
	if(False == os.path.exists(backup_lib_mmsdk_file)):
		print("channelCustomOperBegin() , file ",backup_lib_mmsdk_file,"is not exist!")
		return

	os.remove(umeng_lib_file)
	shutil.copyfile(backup_umeng_noutdid_lib_file,umeng_lib_noutdid_file)
	os.remove(mmsdk_lib_file)

#恢复资源
def channelCustomOperEnd():
	print("end , this is qihoo !")
	checkDirExist()
	
	if(False == os.path.exists(backup_umeng_lib_file)):
		print("channelCustomOperEnd() , file ",backup_umeng_lib_file,"is not exist!")
		return
	if(False == os.path.exists(backup_umeng_noutdid_lib_file)):
		print("channelCustomOperEnd() , file ",backup_umeng_noutdid_lib_file,"is not exist!")
		return
	if(False == os.path.exists(umeng_lib_noutdid_file)):
		print("channelCustomOperEnd() , file ",umeng_lib_noutdid_file,"is not exist!")
		return
	if(False == os.path.exists(backup_lib_mmsdk_file)):
		print("channelCustomOperBegin() , file ",backup_lib_mmsdk_file,"is not exist!")
		return

	os.remove(umeng_lib_noutdid_file)
	shutil.copyfile(backup_umeng_lib_file,umeng_lib_file)
	shutil.copyfile(backup_lib_mmsdk_file,mmsdk_lib_file)
	
if __name__=="__main__":
	if(sys.argv[1] == "begin"):
		channelCustomOperBegin()
	elif(sys.argv[1] == "end"):
		channelCustomOperEnd()
	else:
		raise("call channel custom operation must with param begin or end!")
#	channelCustomOperBegin()
#	channelCustomOperEnd()

